1 using UnityEngine;
2 using
System.Collections;
3 using
System.Collections.Generic;
4 using
UnityEngine.SocialPlatforms;
5
6 public
class GlobalVarManager : MonoBehaviour {
7     
private static GlobalVarManager s_instance = null;
8
9     
const string muteKey = "Mute";
10     
private int muteValue = 0;
11
12     
const string scoreKey = "Score";
13     
private int scoreValue = 0;
14
15     
const string leaderBoard = "hardwings.rank";
16     
17     
public static GlobalVarManager instance {
18         
get {
19             
if (null == s_instance) {
20                 s_instance = FindObjectOfType(
typeof(GlobalVarManager)) as GlobalVarManager;
21                 
if (null == s_instance) {
22                     Debug.Log(
"Fail to get Manager Instance");
23                 }
24             }
25             
return s_instance;
26         }
27     }
28     
29     
public bool GetMuteValue(){
30         
if (muteValue==1) return true;
31         
else return false;
32     }
33     
34     
public void SetMuteValue(bool val){
35         
//Debug.Log("SetMuteValue:"+val);
36         
if (val) muteValue = 1;
37         
else muteValue = 0;
38         SaveMuteFlag(muteValue);
39     }
40     
41     
public int LoadMuteFlag(){
42         
int flag = 0;
43         
if (PlayerPrefs.HasKey(muteKey)) {
44              flag = PlayerPrefs.GetInt(muteKey);
45         }
46         
//Debug.Log("LoadMuteFlag:"+flag);
47         
return flag;
48     }
49     
50     
public void SaveMuteFlag(int flag){
51         PlayerPrefs.SetInt(muteKey, flag);
52         
//Debug.Log("SaveMuteFlag:"+flag);
53     }
54     
55     
public int GetScoreValue(){
56         
return scoreValue;
57     }
58     
59     
public void SetScoreValue(int val){
60         scoreValue = val;
61         SaveScoreRecord(scoreValue);
62     }
63
64     
public int LoadScoreRecord(){
65         
int score = 0;
66         
if (PlayerPrefs.HasKey(scoreKey)) {
67              score = PlayerPrefs.GetInt(scoreKey);
68         }
69         
//Debug.Log("LoadScoreRecord:"+score);
70         
return score;
71     }
72     
73     
public void SaveScoreRecord(int score){
74         
//Debug.Log("SaveScoreRecord : " + score);
75         PlayerPrefs.SetInt(scoreKey, score);
76         ReportScore(leaderBoard, score);
77     }
78
79     
void OnApplicationQuit() {
80         s_instance =
null;
81     }
82  
83     
void Awake () {
84         DontDestroyOnLoad(
this);
85         muteValue = LoadMuteFlag();
86         scoreValue = LoadScoreRecord();
87         Social.localUser.Authenticate (HandleAuthenticated);
88     }
89
90     
private void HandleAuthenticated (bool success) {
91         
if (success) {
92             
//Social.localUser.LoadFriends (HandleFriendsLoaded);
93             
//Social.LoadAchievements (HandleAchievementsLoaded);
94             
//Social.LoadAchievementDescriptions (HandleAchievementDescriptionsLoaded);
95         }
96     }
97
98     
private void HandleFriendsLoaded (bool success) {
99         
foreach (IUserProfile friend in Social.localUser.friends) {
100         }
101     }
102
103     
private void HandleAchievementsLoaded (IAchievement[] achievements) {
104         
foreach (IAchievement achievement in achievements) {
105         }
106     }
107
108     
private void HandleAchievementDescriptionsLoaded (IAchievementDescription[] achievementDescriptions) {
109         
foreach (IAchievementDescription achievementDescription in achievementDescriptions) {
110         }
111     }
112
113     
public void ReportProgress (string achievementId, double progress) {
114         
if (Social.localUser.authenticated) {
115             Social.ReportProgress (achievementId, progress, HandleProgressReported);
116         }
117     }
118     
private void HandleProgressReported (bool success) {
119     }
120
121     
public void ShowAchievements () {
122         
if (Social.localUser.authenticated) {
123             Social.ShowAchievementsUI ();
124         }
125     }
126
127     
public void ReportScore (string leaderboardId, long score) {
128         
if (Social.localUser.authenticated) {
129             Social.ReportScore (score, leaderboardId, HandleScoreReported);
130         }
131     }
132     
public void HandleScoreReported (bool success) {
133     }
134     
public void ShowLeaderboard () {
135         
if (Social.localUser.authenticated) {
136             Social.ShowLeaderboardUI ();
137         }
138     }
139
140     
void Start () {
141     }
142     
143     
void Update () {
144     
145     }
146 }


Debug.Log("SetMuteValue:"+val);

Debug.Log("LoadMuteFlag:"+flag);

Debug.Log("SaveMuteFlag:"+flag);

Debug.Log("LoadScoreRecord:"+score);

Debug.Log("SaveScoreRecord : " + score);

Social.localUser.LoadFriends (HandleFriendsLoaded);

Social.LoadAchievements (HandleAchievementsLoaded);

Social.LoadAchievementDescriptions (HandleAchievementDescriptionsLoaded);




Game đuổi chó sa mạc lập trình bằng ngôn ngữ c# 19.247 lượt xem

Gõ tìm kiếm nhanh...